home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.preview;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JDialog;
- import com.sun.java.swing.SwingUtilities;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.plaf.FileChooserUI;
- import com.sun.java.swing.preview.filechooser.FileFilter;
- import com.sun.java.swing.preview.filechooser.FileSystemView;
- import com.sun.java.swing.preview.filechooser.FileView;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Frame;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.util.Vector;
-
- public class JFileChooser extends JComponent implements Accessible {
- public static final int OPEN_DIALOG = 0;
- public static final int SAVE_DIALOG = 1;
- public static final int CUSTOM_DIALOG = 2;
- public static final int CANCEL_OPTION = 1;
- public static final int APPROVE_OPTION = 0;
- public static final int ERROR_OPTION = 0;
- public static final int FILES_ONLY = 0;
- public static final int DIRECTORIES_ONLY = 1;
- public static final int FILES_AND_DIRECTORIES = 2;
- public static final String CANCEL_SELECTION = "CancelSelection";
- public static final String APPROVE_SELECTION = "ApproveSelection";
- public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty";
- public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty";
- public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged";
- public static final String SELECTED_FILE_CHANGED_PROPERTY = "ApproveSelection";
- public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "fileFilterChanged";
- public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged";
- public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged";
- public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged";
- public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged";
- public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged";
- public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty";
- public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty";
- public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty";
- private String dialogTitle;
- private String approveButtonText;
- private String approveButtonToolTipText;
- private ActionListener actionListener;
- private Vector filters;
- private JDialog dialog;
- private int dialogType;
- private int returnValue;
- private JComponent accessory;
- private FileView fileView;
- private FileView uiFileView;
- private boolean useFileHiding;
- private int fileSelectionMode;
- private boolean multiSelectionEnabled;
- private FileFilter fileFilter;
- private FileSystemView fileSystemView;
- private File currentDirectory;
- private File selectedFile;
- private File[] selectedFiles;
- static Class class$java$awt$event$ActionListener;
- static Class class$java$awt$Frame;
-
- public JFileChooser() {
- this((File)null);
- }
-
- public JFileChooser(File directory) {
- this.dialogTitle = null;
- this.approveButtonText = null;
- this.approveButtonToolTipText = null;
- this.actionListener = null;
- this.filters = new Vector(5);
- this.dialog = null;
- this.dialogType = 0;
- this.returnValue = 0;
- this.accessory = null;
- this.fileView = null;
- this.uiFileView = null;
- this.useFileHiding = true;
- this.fileSelectionMode = 0;
- this.multiSelectionEnabled = false;
- this.fileFilter = null;
- this.fileSystemView = null;
- this.currentDirectory = null;
- this.selectedFile = null;
- this.init();
- this.setCurrentDirectory(directory);
- this.setFileFilter(this.getAcceptAllFileFilter());
- }
-
- public JFileChooser(String path) {
- this.dialogTitle = null;
- this.approveButtonText = null;
- this.approveButtonToolTipText = null;
- this.actionListener = null;
- this.filters = new Vector(5);
- this.dialog = null;
- this.dialogType = 0;
- this.returnValue = 0;
- this.accessory = null;
- this.fileView = null;
- this.uiFileView = null;
- this.useFileHiding = true;
- this.fileSelectionMode = 0;
- this.multiSelectionEnabled = false;
- this.fileFilter = null;
- this.fileSystemView = null;
- this.currentDirectory = null;
- this.selectedFile = null;
- this.init();
- this.setCurrentDirectory(this.getFileSystemView().createFileObject(path));
- this.setFileFilter(this.getAcceptAllFileFilter());
- }
-
- public boolean accept(File f) {
- boolean shown = true;
- if (this.fileFilter != null) {
- shown = this.fileFilter.accept(f);
- }
-
- return shown;
- }
-
- public void addActionListener(ActionListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$java$awt$event$ActionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.awt.event.ActionListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$java$awt$event$ActionListener = var10001;
- }
-
- var10000.add(var10001, l);
- }
-
- public void addChoosableFileFilter(FileFilter filter) {
- if (!this.filters.contains(filter)) {
- FileFilter[] oldValue = this.getChoosableFileFilters();
- this.filters.addElement(filter);
- ((JComponent)this).firePropertyChange("ChoosableFileFilterChangedProperty", oldValue, this.getChoosableFileFilters());
- }
-
- }
-
- public void approveSelection() {
- this.returnValue = 0;
- if (this.dialog != null) {
- this.dialog.setVisible(false);
- }
-
- this.fireActionPerformed("ApproveSelection");
- }
-
- public void cancelSelection() {
- this.returnValue = 1;
- if (this.dialog != null) {
- this.dialog.setVisible(false);
- }
-
- this.fireActionPerformed("CancelSelection");
- }
-
- public void changeToParentDirectory() {
- File oldValue = this.getCurrentDirectory();
- this.setCurrentDirectory(this.getFileSystemView().getParentDirectory(oldValue));
- }
-
- public void ensureFileIsVisible(File f) {
- this.getUI().ensureFileIsVisible(f);
- }
-
- protected void fireActionPerformed(String command) {
- Object[] listeners = super.listenerList.getListenerList();
- ActionEvent e = null;
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$java$awt$event$ActionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.awt.event.ActionListener");
- } catch (ClassNotFoundException var5) {
- throw new NoClassDefFoundError(((Throwable)var5).getMessage());
- }
-
- class$java$awt$event$ActionListener = var10001;
- }
-
- if (var10000 == var10001) {
- if (e == null) {
- e = new ActionEvent(this, 1001, command);
- }
-
- ((ActionListener)listeners[i + 1]).actionPerformed(e);
- }
- }
-
- }
-
- public FileFilter getAcceptAllFileFilter() {
- FileFilter filter = null;
- if (this.getUI() != null) {
- filter = this.getUI().getAcceptAllFileFilter();
- }
-
- return filter;
- }
-
- public JComponent getAccessory() {
- return this.accessory;
- }
-
- public String getApproveButtonText() {
- return this.approveButtonText;
- }
-
- public String getApproveButtonToolTipText() {
- return this.approveButtonToolTipText;
- }
-
- public FileFilter[] getChoosableFileFilters() {
- FileFilter[] filterArray = new FileFilter[this.filters.size()];
- this.filters.copyInto(filterArray);
- return filterArray;
- }
-
- public File getCurrentDirectory() {
- return this.currentDirectory;
- }
-
- public String getDescription(File f) {
- String description = null;
- if (this.getFileView() != null) {
- description = this.getFileView().getDescription(f);
- }
-
- if (description == null && this.uiFileView != null) {
- description = this.uiFileView.getDescription(f);
- }
-
- return description;
- }
-
- public String getDialogTitle() {
- return this.dialogTitle;
- }
-
- public int getDialogType() {
- return this.dialogType;
- }
-
- public FileFilter getFileFilter() {
- return this.fileFilter;
- }
-
- public int getFileSelectionMode() {
- return this.fileSelectionMode;
- }
-
- public FileSystemView getFileSystemView() {
- return this.fileSystemView;
- }
-
- public FileView getFileView() {
- return this.fileView;
- }
-
- public Icon getIcon(File f) {
- Icon icon = null;
- if (this.getFileView() != null) {
- icon = this.getFileView().getIcon(f);
- }
-
- if (icon == null && this.uiFileView != null) {
- icon = this.uiFileView.getIcon(f);
- }
-
- return icon;
- }
-
- public String getName(File f) {
- String filename = null;
- if (this.getFileView() != null) {
- filename = this.getFileView().getName(f);
- }
-
- if (filename == null && this.uiFileView != null) {
- filename = this.uiFileView.getName(f);
- }
-
- return filename;
- }
-
- public File getSelectedFile() {
- return this.selectedFile;
- }
-
- public File[] getSelectedFiles() {
- return this.selectedFiles == null ? new File[0] : (File[])this.selectedFiles.clone();
- }
-
- public String getTypeDescription(File f) {
- String typeDescription = null;
- if (this.getFileView() != null) {
- typeDescription = this.getFileView().getTypeDescription(f);
- }
-
- if (typeDescription == null && this.uiFileView != null) {
- typeDescription = this.uiFileView.getTypeDescription(f);
- }
-
- return typeDescription;
- }
-
- public FileChooserUI getUI() {
- return (FileChooserUI)super.ui;
- }
-
- public String getUIClassID() {
- return "FileChooserUI";
- }
-
- protected void init() {
- this.setFileSystemView(FileSystemView.getFileSystemView());
- this.updateUI();
- }
-
- public boolean isDirectorySelectionEnabled() {
- return this.fileSelectionMode == 1 || this.fileSelectionMode == 2;
- }
-
- public boolean isFileHidingEnabled() {
- return this.useFileHiding;
- }
-
- public boolean isFileSelectionEnabled() {
- return this.fileSelectionMode == 0 || this.fileSelectionMode == 2;
- }
-
- public boolean isMultiSelectionEnabled() {
- return this.multiSelectionEnabled;
- }
-
- public boolean isTraversable(File f) {
- Boolean traversable = null;
- if (this.getFileView() != null) {
- traversable = this.getFileView().isTraversable(f);
- }
-
- if (traversable == null && this.uiFileView != null) {
- traversable = this.uiFileView.isTraversable(f);
- }
-
- if (traversable == null && f != null) {
- if (f.isDirectory()) {
- traversable = Boolean.TRUE;
- } else {
- traversable = Boolean.FALSE;
- }
- } else if (traversable == null) {
- return false;
- }
-
- return traversable;
- }
-
- public void removeActionListener(ActionListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$java$awt$event$ActionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.awt.event.ActionListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$java$awt$event$ActionListener = var10001;
- }
-
- var10000.remove(var10001, l);
- }
-
- public boolean removeChoosableFileFilter(FileFilter f) {
- if (this.filters.contains(f)) {
- FileFilter[] oldValue = this.getChoosableFileFilters();
- this.filters.removeElement(f);
- ((JComponent)this).firePropertyChange("ChoosableFileFilterChangedProperty", oldValue, this.getChoosableFileFilters());
- return true;
- } else {
- return false;
- }
- }
-
- public void rescanCurrentDirectory() {
- this.getUI().rescanCurrentDirectory();
- }
-
- public void resetChoosableFileFilters() {
- FileFilter[] oldValue = this.getChoosableFileFilters();
- this.filters.removeAllElements();
- this.filters.addElement(this.getAcceptAllFileFilter());
- ((JComponent)this).firePropertyChange("ChoosableFileFilterChangedProperty", oldValue, this.getChoosableFileFilters());
- }
-
- public void setAccessory(JComponent newAccessory) {
- JComponent oldValue = this.accessory;
- this.accessory = newAccessory;
- ((JComponent)this).firePropertyChange("AccessoryChangedProperty", oldValue, this.accessory);
- }
-
- public void setApproveButtonText(String approveButtonText) {
- if (this.approveButtonText != approveButtonText) {
- String oldValue = this.approveButtonText;
- this.approveButtonText = approveButtonText;
- this.setDialogType(2);
- ((JComponent)this).firePropertyChange("ApproveButtonTextChangedProperty", oldValue, approveButtonText);
- }
- }
-
- public void setApproveButtonToolTipText(String toolTipText) {
- if (this.approveButtonToolTipText != toolTipText) {
- String oldValue = this.approveButtonToolTipText;
- this.approveButtonToolTipText = toolTipText;
- this.setDialogType(2);
- ((JComponent)this).firePropertyChange("ApproveButtonToolTipTextChangedProperty", oldValue, this.approveButtonToolTipText);
- }
- }
-
- public void setCurrentDirectory(File dir) {
- if (this.currentDirectory != dir || dir == null) {
- File oldValue = this.currentDirectory;
- if (dir == null) {
- this.currentDirectory = this.getFileSystemView().createFileObject(System.getProperty("user.home"));
- } else {
- for(File prev = null; !this.isTraversable(dir) && prev != dir && !this.getFileSystemView().isRoot(dir); dir = this.getFileSystemView().getParentDirectory(dir)) {
- prev = dir;
- }
-
- this.currentDirectory = dir;
- }
-
- ((JComponent)this).firePropertyChange("directoryChanged", oldValue, this.currentDirectory);
- }
- }
-
- public void setDialogTitle(String dialogTitle) {
- this.dialogTitle = dialogTitle;
- if (this.dialog != null) {
- this.dialog.setTitle(dialogTitle);
- }
-
- }
-
- public void setDialogType(int dialogType) {
- if (this.dialogType != dialogType) {
- if (dialogType != 0 && dialogType != 1 && dialogType != 2) {
- throw new IllegalArgumentException("Incorrect Dialog Type: " + dialogType);
- } else {
- int oldValue = this.dialogType;
- this.dialogType = dialogType;
- if (dialogType == 0 || dialogType == 1) {
- this.setApproveButtonText((String)null);
- }
-
- ((JComponent)this).firePropertyChange("DialogTypeChangedProperty", oldValue, dialogType);
- }
- }
- }
-
- public void setFileFilter(FileFilter filter) {
- FileFilter oldValue = this.fileFilter;
- this.fileFilter = filter;
- ((JComponent)this).firePropertyChange("fileFilterChanged", oldValue, this.fileFilter);
- }
-
- public void setFileHidingEnabled(boolean b) {
- boolean oldValue = this.useFileHiding;
- this.useFileHiding = b;
- ((JComponent)this).firePropertyChange("FileHidingChanged", oldValue, this.useFileHiding);
- }
-
- public void setFileSelectionMode(int mode) {
- if (this.fileSelectionMode != mode) {
- int oldValue = this.fileSelectionMode;
- this.fileSelectionMode = mode;
- ((JComponent)this).firePropertyChange("fileSelectionChanged", oldValue, this.fileSelectionMode);
- }
- }
-
- public void setFileSystemView(FileSystemView fileSystemView) {
- FileSystemView oldValue = this.fileSystemView;
- this.fileSystemView = fileSystemView;
- ((JComponent)this).firePropertyChange("FileSystemViewChanged", oldValue, fileSystemView);
- }
-
- public void setFileView(FileView fileView) {
- FileView oldValue = this.fileView;
- this.fileView = fileView;
- ((JComponent)this).firePropertyChange("fileViewChanged", oldValue, fileView);
- }
-
- public void setMultiSelectionEnabled(boolean b) {
- if (this.multiSelectionEnabled != b) {
- boolean oldValue = this.multiSelectionEnabled;
- this.multiSelectionEnabled = b;
- ((JComponent)this).firePropertyChange("fileFilterChanged", oldValue, this.multiSelectionEnabled);
- }
- }
-
- public void setSelectedFile(File selectedFile) {
- File oldValue = this.selectedFile;
- this.selectedFile = selectedFile;
- this.ensureFileIsVisible(selectedFile);
- ((JComponent)this).firePropertyChange("ApproveSelection", oldValue, this.selectedFile);
- }
-
- public void setSelectedFiles(File[] selectedFiles) {
- this.selectedFiles = selectedFiles;
- }
-
- public int showDialog(Component parent, String approveButtonText) {
- if (approveButtonText != null) {
- this.setApproveButtonText(approveButtonText);
- }
-
- Frame var10000;
- if (parent instanceof Frame) {
- var10000 = (Frame)parent;
- } else {
- Class var6 = class$java$awt$Frame;
- if (var6 == null) {
- try {
- var6 = Class.forName("java.awt.Frame");
- } catch (ClassNotFoundException var5) {
- throw new NoClassDefFoundError(((Throwable)var5).getMessage());
- }
-
- class$java$awt$Frame = var6;
- }
-
- var10000 = (Frame)SwingUtilities.getAncestorOfClass(var6, parent);
- }
-
- Frame frame = var10000;
- this.dialog = new JDialog(frame, this.getDialogTitle(), true);
- Container contentPane = this.dialog.getContentPane();
- contentPane.setLayout(new BorderLayout());
- contentPane.add(this, "Center");
- this.dialog.pack();
- this.dialog.setLocationRelativeTo(parent);
- this.dialog.show();
- return this.returnValue;
- }
-
- public int showOpenDialog(Component parent) {
- this.setDialogType(0);
- return this.showDialog(parent, (String)null);
- }
-
- public int showSaveDialog(Component parent) {
- this.setDialogType(1);
- return this.showDialog(parent, (String)null);
- }
-
- public void updateUI() {
- ((JComponent)this).setUI((FileChooserUI)UIManager.getUI(this));
- this.uiFileView = this.getUI().getFileView();
- boolean useAcceptAllFileFilter = this.removeChoosableFileFilter(this.getAcceptAllFileFilter());
- if (useAcceptAllFileFilter) {
- this.addChoosableFileFilter(this.getAcceptAllFileFilter());
- }
-
- }
- }
-